package com.weitu.risk.controller;

import com.weitu.base.controller.BaseController;
import com.weitu.paging.DataGridPagination;
import com.weitu.plugin.PageView;
import com.weitu.risk.service.StatisticsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 风险统计模块Controller
 * Created by fanyuting on 2017/5/15 0015.
 */
@Controller
@RequestMapping("risk/statistics")
public class StatisticsController extends BaseController {
    private static final String MODULE_BATH_PATH = BASE_JSP_PATH + "risk/statistics/";
    @Autowired
    private StatisticsService statisticsService;

    /**
     * 跳转到通过风险等级统计页面
     *
     * @param request
     * @return
     */
    @RequestMapping("/riskGrade/list")
    public String toStatisticsByRiskRradePage(HttpServletRequest request) {
        return this.MODULE_BATH_PATH + "riskGrade";
    }

    /**
     * 通过风险等级统计
     *
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping("statisticsListByRiskGrade")
    public Object statisticsByRiskGrade(HttpServletRequest request) {
        Map<String, Object> map = new HashMap<String, Object>();
        //获取前台参数
        putParametersIntoMap(map);
        Integer totalNum = this.statisticsService.statisticsByRiskGradeCount(map);//获取总数
        DataGridPagination pagination = DataGridPagination.getInstance(request, totalNum);
        PageView pageView = pagination.getPageView();//生成pageView分页对象
        map.put("pageView", pageView);
        List<Map<String, Object>> list = this.statisticsService.statisticsByRiskGradeList(map);
        return pagination.flushDataGridData(list);
    }

    /**
     * 通过风险识别对象类型
     *
     * @param request
     * @return
     */
    @RequestMapping("/recogniseType/list")
    public String toStatisticsByRecogniseTypePage(HttpServletRequest request) {
        return this.MODULE_BATH_PATH + "recogniseType";
    }

    /**
     * 通过风险等级统计
     *
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping("statisticsByRecogniseType")
    public Object statisticsByRecogniseType(HttpServletRequest request) {
        Map<String, Object> map = new HashMap<String, Object>();
        //获取前台参数
        putParametersIntoMap(map);
        Integer totalNum = this.statisticsService.statisticsByRecogniseTypeCount(map);//获取总数
        DataGridPagination pagination = DataGridPagination.getInstance(request, totalNum);
        PageView pageView = pagination.getPageView();//生成pageView分页对象
        map.put("pageView", pageView);
        List<Map<String, Object>> list = this.statisticsService.statisticsByRecogniseTypeList(map);
        return pagination.flushDataGridData(list);
    }

    /**
     * 通过风险类别统计
     *
     * @param request
     * @return
     */
    @RequestMapping("/riskType/list")
    public String toStatisticsByRiskTypePage(HttpServletRequest request) {
        return this.MODULE_BATH_PATH + "riskType";
    }

    /**
     * 通过风险等级统计
     *
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping("statisticsByRiskType")
    public Object statisticsByRiskType(HttpServletRequest request) {
        Map<String, Object> map = new HashMap<String, Object>();
        //获取前台参数
        putParametersIntoMap(map);
        Integer totalNum = this.statisticsService.statisticsByRiskTypeCount(map);//获取总数
        DataGridPagination pagination = DataGridPagination.getInstance(request, totalNum);
        PageView pageView = pagination.getPageView();//生成pageView分页对象
        map.put("pageView", pageView);
        List<Map<String, Object>> list = this.statisticsService.statisticsByRiskTypeList(map);
        return pagination.flushDataGridData(list);
    }

    /**
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping("statisticsBySeriousState")
    public Object statisticsBySeriousState(HttpServletRequest request) {
        Map<String, Object> map = new HashMap<String, Object>();
        putParametersIntoMap(map);
        return this.statisticsService.statisticsBySeriousState(map);
    }

}
